package com.ruoyi.cmdb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cmdb.domain.ServiceInstanceStatus;
import com.ruoyi.cmdb.service.IServiceInstanceStatusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务实例的状态Controller
 * 
 * @author ruoyi
 * @date 2023-01-29
 */
@RestController
@RequestMapping("/cmdb/status")
public class ServiceInstanceStatusController extends BaseController
{
    @Autowired
    private IServiceInstanceStatusService serviceInstanceStatusService;

    /**
     * 查询服务实例的状态列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceInstanceStatus serviceInstanceStatus)
    {
        startPage();
        List<ServiceInstanceStatus> list = serviceInstanceStatusService.selectServiceInstanceStatusList(serviceInstanceStatus);
        return getDataTable(list);
    }

    /**
     * 导出服务实例的状态列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:export')")
    @Log(title = "服务实例的状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceInstanceStatus serviceInstanceStatus)
    {
        List<ServiceInstanceStatus> list = serviceInstanceStatusService.selectServiceInstanceStatusList(serviceInstanceStatus);
        ExcelUtil<ServiceInstanceStatus> util = new ExcelUtil<ServiceInstanceStatus>(ServiceInstanceStatus.class);
        util.exportExcel(response, list, "服务实例的状态数据");
    }

    /**
     * 获取服务实例的状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(serviceInstanceStatusService.selectServiceInstanceStatusById(id));
    }

    /**
     * 新增服务实例的状态
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:add')")
    @Log(title = "服务实例的状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceInstanceStatus serviceInstanceStatus)
    {
        return toAjax(serviceInstanceStatusService.insertServiceInstanceStatus(serviceInstanceStatus));
    }

    /**
     * 修改服务实例的状态
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:edit')")
    @Log(title = "服务实例的状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceInstanceStatus serviceInstanceStatus)
    {
        return toAjax(serviceInstanceStatusService.updateServiceInstanceStatus(serviceInstanceStatus));
    }

    /**
     * 删除服务实例的状态
     */
    @PreAuthorize("@ss.hasPermi('cmdb:status:remove')")
    @Log(title = "服务实例的状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(serviceInstanceStatusService.deleteServiceInstanceStatusByIds(ids));
    }
}
